/*
 * CrossoverStrategyBlend.h
 *
 *  Created on: Oct 22, 2013
 *      Author: filipe
 */

#ifndef CROSSOVERSTRATEGYBLEND_H_
#define CROSSOVERSTRATEGYBLEND_H_

#include "CrossoverStrategy.h"

namespace EvolutionaryOptimization
{
	class CrossoverStrategyBlend : public EvolutionaryOptimization::CrossoverStrategy<double>
	{
		double _Alpha;

		public:


			// TODO: create a constructor that received the _Alpha
			CrossoverStrategyBlend(int dimension) : CrossoverStrategy(dimension)
			{
				_Alpha = 0.5;
				srand(time(NULL));
			}


			~CrossoverStrategyBlend()
			{
			}


			void
			PerformCrossover(double *child1, double *child2) const
			{
				double beta;
				double x;
				double y;

				for (int i = 0; i < _Dimension; i++)
				{
					beta = ((double) rand()) / ((double) RAND_MAX) + _Alpha;

					x = child1[i] + beta * (child2[i] - child1[i]);
					y = child2[i] + beta * (child1[i] - child2[i]);

					child1[i] = x;
					child2[i] = y;
				}
			}
	};
}

#endif
